package com.panda.pandawash.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.method.DigitsKeyListener;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.panda.pandawash.R;

/**
 * Created by gaowf on 2017/2/25.
 */

public class UnBindDialog extends Dialog {
    private Button yes;
    private Button no;
    private TextView titleTv;
    private TextView messageTv;
    private TextView Unit;
    private RelativeLayout layoutUnit;
    private String titleStr;
    private String messageStr;
    private String valueString;
    private int myVisible = -1;
    private int myLayoutVisible = -1;
    private String yesStr;
    private String noStr;
    private EditText editText;
    private RelativeLayout viewInput;
    private UnBindDialog.onNoOnclickListener noOnclickListener;
    private UnBindDialog.onYesOnclickListener yesOnclickListener;
    private String digits;
    private int input_type = -1;
    public static int SELFDIALOG_EDIT_TYPE_EMPTY = -1;
    private String unit;

    public void setNoOnclickListener(String str, UnBindDialog.onNoOnclickListener onNoOnclickListener) {
        if(str != null) {
            this.noStr = str;
        }
        this.noOnclickListener = onNoOnclickListener;
    }

    public void setYesOnclickListener(String str, UnBindDialog.onYesOnclickListener onYesOnclickListener) {
        if(str != null) {
            this.yesStr = str;
        }
        this.yesOnclickListener = onYesOnclickListener;
    }

    public UnBindDialog(Context context) {
        super(context);
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.free_exercise_sure_dialog_layout);
        this.setCanceledOnTouchOutside(false);
        this.initView();
        this.initData();
        this.initEvent();
    }

    private void initEvent() {
        yes.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(UnBindDialog.this.yesOnclickListener != null) {
                    String editString = null;
                    boolean flg = false;
                    editString = UnBindDialog.this.editText.getText().toString();
                    Object times;
                    if(String.valueOf(editString) != null && !editString.equals("")) {
                        times = editString;
                        flg = true;
                    } else {
                        times = Integer.valueOf(-1);
                    }

                    UnBindDialog.this.yesOnclickListener.onYesClick(times, flg);
                }

            }
        });
        this.no.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                if(UnBindDialog.this.noOnclickListener != null) {
                    UnBindDialog.this.noOnclickListener.onNoClick();
                }

            }
        });
    }

    private void initData() {
        if(this.titleStr != null) {
            this.titleTv.setText(this.titleStr);
        }

        if(this.messageStr != null) {
            this.messageTv.setText(this.messageStr);
        }

        if(this.yesStr != null) {
            this.yes.setText(this.yesStr);
        }

        if(this.noStr != null) {
            this.no.setText(this.noStr);
        }

        if(this.myVisible >= 0) {
            this.viewInput.setVisibility(View.GONE);
        }

        if(this.myLayoutVisible >= 0) {
            this.layoutUnit.setVisibility(View.INVISIBLE);
        }

        if(this.digits != null && !this.digits.equals("")) {
            this.editText.setKeyListener(DigitsKeyListener.getInstance(this.digits));
        }

        if(this.input_type != -1) {
            this.editText.setInputType(Integer.valueOf(this.input_type).intValue());
        }

        if(this.unit != null) {
            this.Unit.setText(this.unit);
        }

        if(this.valueString != null) {
            this.editText.setText(this.valueString);
            this.editText.setSelection(this.valueString.length());
        }

    }

    private void initView() {
        this.yes = (Button)this.findViewById(R.id.yes);
        this.no = (Button)this.findViewById(R.id.no);
        this.titleTv = (TextView)this.findViewById(R.id.title);
        this.messageTv = (TextView)this.findViewById(R.id.message);
        this.editText = (EditText)this.findViewById(R.id.edit_time_input);
        this.viewInput = (RelativeLayout)this.findViewById(R.id.view_input);
        this.Unit = (TextView)this.findViewById(R.id.time_unit);
        this.layoutUnit = (RelativeLayout)this.findViewById(R.id.layout_unit);
    }

    public void setTitle(String title) {
        this.titleStr = title;
    }

    public void setMessage(String message) {
        this.messageStr = message;
    }

    public void setEditVisibility(int visible) {
        this.myVisible = visible;
    }

    public void setEditText(String str) {
        this.valueString = str;
    }

    public void setUnitLayoutVisibility(int myLayoutVisible) {
        this.myLayoutVisible = myLayoutVisible;
    }

    public void setUinit(String unit) {
        this.unit = unit;
    }

    public void setEditDigits(String digits) {
        this.digits = digits;
    }

    public void setEditType(int input_type) {
        this.input_type = input_type;
    }

    public interface onNoOnclickListener {
        void onNoClick();
    }

    public interface onYesOnclickListener {
        void onYesClick(Object var1, boolean var2);
    }
}

